using System;
using System.Diagnostics;
using System.Windows.Forms;
using System.IO;

namespace Departure
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [MTAThread]
        static void Main()
        {
#if DEBUG
            Debug.WriteLine("Starting: " + DateTime.Now.ToString());
#endif

#if DEBUG
            Application.Run(new frmMain());
#else
            
            try
            {
                Application.Run(new frmMain());
            }
            catch (Exception ex)
            {
                string exception = ExceptionHandling.ConstructFullExceptionChainString(ex);
                string appPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
                string filename = "Crash" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".txt";
                
                using (StreamWriter sw = new StreamWriter(appPath + "\\"+ filename))
                {
                    sw.Write(exception);
                    sw.Flush();
                }

                Process p = new Process();
                p.StartInfo = new ProcessStartInfo(appPath + "\\CrashReporter.exe", filename);
                p.Start();
            }
#endif
        }
    }

}